// pages/aduting/resversion/reversion_detail.js
var util = require('../../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    room_id:'',
    hiddenmodalput:true,
    reject_cause:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getStorage({
      key: 'userInfo',
      success: function (res) {
        that.setData({
          userInfo: res.data,
          id: options.id,
          room_id: options.room_id
        })

        util.getReq("/app/my/reservationDetail", {
          source: res.data.source,
          uid: res.data.uid,
          'reservation.reservation_id': that.data.id
        
        },function(datas){
            if(datas.code==0){
              console.log(datas.data.reservation_time);
              that.setData({
                  resversionDetail:datas.data,
                  reservation_time: util.format(datas.data.reservation_time,'yyyy-MM-dd')
                 
              })

            }else {
              wx.showToast({
                title: datas.desc,
              })
            }

        })
      }, fail: function () {
        wx.redirectTo({
          url: '/pages/index/index',
        })
      }
    });
  },
  bindAgree:function(e) {
    var that = this;
    wx.showModal({
      title: '同意预约？',
      content: '确定同意这张预约单？',
      success: function (res) {
        if (res.confirm) {
          var userInfo = that.data.userInfo
          util.getReq('/app/my/shenHeReservation',
           { uid: userInfo.uid, 
           source: userInfo.source,
           'reservation.reservation_id':that.data.id,
            'reservation.room_id': that.data.room_id,
            'reservation.reservation_state':1,
            'reservation.check_user': userInfo.uid,
            'reservation.ifFdApp':true,
            'reservation.reject_cause':'',
            'user.user_id': userInfo.uid,
            'user.user_name': userInfo.name,
            'user.phone_num': userInfo.mobile
             }, function (data) {
            if (data.code == 0) {
              
              wx.redirectTo({
                url: '/pages/aduting/resversion/resersion_list',
              })
            } else {
              util.isError('同意失败', that);
              return false;
            }
          })
        }
      }
    })
  },
  bindRelse:function(e){
    var that = this;
    that.setData({
      hiddenmodalput:false

    })

  },
  cancelM: function (e) {
    this.setData({
      hiddenmodalput: true,
    })
  },

  confirmM: function (e) {
    var that=this;
    var userInfo = that.data.userInfo;
    util.getReq('/app/my/shenHeReservation',
      {
        uid: userInfo.uid,
        source: userInfo.source,
        'reservation.reservation_id': that.data.id,
        'reservation.room_id': that.data.room_id,
        'reservation.reservation_state': 2,
        'reservation.check_user': userInfo.uid,
        'reservation.ifFdApp': true,
        'reservation.reject_cause': that.data.reject_cause,
        'user.user_id': userInfo.uid,
        'user.user_name': userInfo.name,
        'user.phone_num': userInfo.mobile
      }, function (data) {
        if (data.code == 0) {

          wx.redirectTo({
            url: '/pages/aduting/resversion/resersion_list',
          })
        } else {
          util.isError('拒绝失败', that);
          return false;
        }
      })
  },
  reject_cause:function(e){
      this.setData({
        reject_cause:e.detail.value

      })

  }
})